#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

// callback函数  回调函数
void task1(int flags) {
	for (int i = 0; i < 5; ++i) {
		printf("task running: %d\n", flags);
		sleep(1);
	}
	pthread_exit(NULL);
}

int main() {
	pthread_t tid1, tid2;
	// void *(*start_routine)(void *) 
	int ret = pthread_create(&tid1, NULL, (void *(*)(void *))task1, (void *)100);
	if (ret ) {
		perror("pthread_create");
		exit(-1);
	}
	printf("main process[%d] create thread: %lu\n", getpid(), tid1);

	ret = pthread_create(&tid2, NULL, (void *(*)(void *))task1, (void *)200);
	if (ret ) {
		perror("pthread_create");
		exit(-1);
	}
	printf("main process[%d] create thread: %lu\n", getpid(), tid2);
	pthread_join(tid1, NULL);
	pthread_join(tid2, NULL);
	printf("main process exit!\n");
	return 0;
}